﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/VirtualMachines.Master" AutoEventWireup="true" CodeBehind="VirtualMachines.aspx.cs" Inherits="OctopusWebInterface.VirtualMachines" Theme="VirtualMachines" %>

<asp:Content ID="Content1" ContentPlaceholderId="mainContent" runat="server">

<!--<script type="text/javascript" src="OnloadScheduler.js"></script>-->
<script type="text/javascript" src="scripts/VirtualMachines.js"></script>

<script type="text/javascript">
    function OnPageLoad() {
        var callbk = function (readyState, status, responseText) {
            if (readyState == 4) {
                if (status == 200) {
                    // TODO: check this eval... I could use json here
                    var allVm = eval(responseText);
                    document.getElementById("VirtualMachines").innerHTML = "";

                    for (i = 0; i < allVm.length; i += 5) {
                        var vmGuid = allVm[i];
                        var vmName = allVm[i + 1];
                        var vmState = allVm[i + 2];
                        var cpuCores = allVm[i + 3];
                        var ramAmount = allVm[i + 4];

                        // name patch
                        if (vmState == "ScheduledForCreation") vmState = "Scheduled";

                        var tile = buildVmTile(vmGuid, vmName, cpuCores, ramAmount, vmState);

                        new DisplayTileTask(tile).DoAction(0);
                        AnimeJGlobalTimer.SetAlertMillis(new ApplyVmTileStyleTask(vmGuid, vmState, vmName), 50);

                        var code = "invokeGetVmStatus(\"" + vmGuid + "\", \"" + vmName + "\")";
                        setInterval(code, 30000);
                    }
                }
                else {
                    document.getElementById("VirtualMachines").innerHTML = "Unable to load the virtual machines";
                }
            }
        };

        var url = "GetAjax.aspx?func=getUserVm";
        executeAjax(url, callbk);
    }
</script>


<div style="margin-top:60px; text-align:center">
<%--
    <asp:LoginName ID="LoginName1" runat="server" Visible="false" />
--%>
    <div id="ContentTiles" style="text-align: center">
        <div id="Messages" class="VMInfo">
            Messages:<br />
            <div id="divMessages"></div>
        </div>
        <span id="VirtualMachines">
            <div class="VMInfo">Loading...</div>
        </span>
        <div class="VMInfo">
            &nbsp;<div id="OpenNewVM"><img alt="" src="Images/new.png" style="cursor:hand" onclick="OctopusNewVM(this)"/></div>
        </div>
    </div>

    <img id="Banner" src="Images/banner.png" alt="" style="position: absolute; left: 250px; top: 0px; z-index: -100;" />

    <div id="NewVM">
        <dl class="newVmDl">
            <dt>Template</dt>
            <dd>
                <asp:DropDownList ID="DropDownList_VmTemplates" onchange="vmTemplatesChanged(this)" runat="server"></asp:DropDownList>
                <br />
                <span id="vmTemplate_Descr"></span>
                <br />
                <input type="hidden" value="" id="vmTemplate_Id" />
            </dd>

            <dt>Number of CPU cores</dt>
            <dd><input type="text" id="input_cpuCores" style="width:34px" /></dd>
            <dt>Ram amount</dt>
            <dd><input type="text" id="input_ramAmount" style="width:49px" /> MB</dd>
            <dt>VM name</dt>
            <dd><input type="text" id="input_vmName" style="width:215px" onchange="check_vmName()" /><span id="note_vmName">()</span></dd>
            <dt>Machine name</dt>
            <dd><input type="text" id="input_hostName" onchange="check_hostName()" /><span id="note_hostName">()</span></dd>
            <dt>Administrator's password</dt>
            <dd><input type="password" id="input_adminPass" /></dd>
        </dl>

        <div class="newVmButtons">
            <input type="button" value="Create" onclick="createNewVm()" />
            &nbsp;<input type="button" id="CancelNewVM" value="Cancel" onclick="OctopusHideNewVM(this)" />
        </div>
    </div>  

</div>    
</asp:Content>